﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcContrib.UI.Html;


namespace System.Web.Mvc
{
    public static class jQueryHelpers
    {
        public static string RenderjQueryIcon(this HtmlHelper helper, string containerCssClass,string iconCssClass,string title, string onClickString,string htmlattributes)
        { 
            StringBuilder sb=new StringBuilder();

            string strClickString=string.Empty;
            if(!string.IsNullOrEmpty(strClickString))
             strClickString = string.Format(" onclick='{0}'", onClickString);
            
            sb.AppendFormat("<div style='height:18px;width:18px;' title='{0}' class='ui-state-default ui-corner-all {3}'{1}{2}>",title,onClickString,htmlattributes,containerCssClass);
            sb.AppendFormat("<span class='ui-icon {0}'></span>",iconCssClass);
            sb.Append("</div>");
            return sb.ToString();
        }

        public static string RenderjQueryErrorDiv(this HtmlHelper helper, string msg, string styleString)
        {
            StringBuilder sb = new StringBuilder();
            if (styleString == null)
                styleString = string.Empty;

            sb.AppendFormat("<div class=\"ui-state-error ui-corner-all jQueryErrorDiv\" style=\"{0}\">", styleString);
            sb.Append("<span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\"></span>");
            sb.Append(msg);
            sb.Append("</div>");

            return sb.ToString();        
        }

        public static string RenderjQueryInfoDiv(this HtmlHelper helper, string msg, string styleString)
        {
            StringBuilder sb = new StringBuilder();
            if (styleString == null)
                styleString = string.Empty;

            sb.AppendFormat("<div class=\"ui-state-highlight ui-corner-all jQueryInfoDiv\" style=\"{0}\">", styleString);
            sb.Append("<span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\"></span>");
            sb.Append(msg);
            sb.Append("</div>");

            return sb.ToString();
        }
        public static string GetjqGridCulture(this HtmlHelper htmlhelper)
        {
            return GetjQueryCulture();
        }
        internal static string GetjQueryCulture()
        {
            string culture = ResourceHtmlHelpers.GetCulture();
            switch (culture)
            {
                case "en-us":
                    return "en";
                case "zh-cn":
                    return "cn";
                default:
                    return "en";
            }
        }

        public static string jQueryValidateScriptInclude(this HtmlHelper htmlhelper)
        {
            return HtmlHelperExtensions.ScriptInclude(htmlhelper,string.Format("~/Scripts/jquery-validate/jquery.validate.min.js",GetjQueryCulture()))+
                HtmlHelperExtensions.ScriptInclude(htmlhelper, string.Format("~/Scripts/jquery-validate/localization/messages_{0}.js", GetjQueryCulture()));
        }
    }
}
